<!-- script代码，如果需要引用js文件，请使用与HTML中相同的方式。 -->
<script type="text/javascript">
    /*
    *  TODO
     *  请在此处编写javascript代码
     */
	 
	 
	//变动生效日期
	var zgsxrqfield = "field9836";
	//考核开始日期
	//var khksrqfield = "field9827";
	var khksrqfield = "field987";
	//考核期限
	var khqxfield = "field9826";
	//考核到期日
	var khdqrfield = "field9828";
	

	function getNextMonth(date,months) {  
	    var arr = date.split('-');  
	    var year = arr[0]; //获取当前日期的年份  
	    var month = arr[1]; //获取当前日期的月份  
	    var day = arr[2]; //获取当前日期的日  
	    var days = new Date(year, month, 0);  
	    days = days.getDate(); //获取当前日期中的月的天数  
	    var year2 = year;  
	    var month2 = parseInt(month) + months;  
	    if (month2 == 13) {  
	        year2 = parseInt(year2) + 1;  
	        month2 = 1;  
	    }  
	    if (month2 == 14) {  
	        year2 = parseInt(year2) + 1;  
	        month2 = 2;  
	    }  
	    if (month2 == 15) {  
	        year2 = parseInt(year2) + 1;  
	        month2 = 3;  
	    } 
	    var day2 = day;  
	    var days2 = new Date(year2, month2, 0);  
	    days2 = days2.getDate();  
	    if (day2 > days2) {  
	        day2 = days2;  
	    }  
	    if (month2 < 10) {  
	        month2 = '0' + month2;  
	    }  
	  
	    var t2 = year2 + '-' + month2 + '-' + day2;  
	    return t2;  
	}



	function addDate1(date,days){
	    var d=new Date(date);
	    d.setDate(d.getDate()+days);
	    var month=d.getMonth()+1;
	    var day = d.getDate();
	    if(month<10){
	    	month = "0"+month;
	    }
	    if(day<10){
	    	day = "0"+day;
	    }
	    var val = d.getFullYear()+"-"+month+"-"+day;
	    return val;
	}
	
	
	function addDate(date, days) {
		if(days == undefined || days == '') {
			days = 1;
		}
		var date = new Date(date);
		date.setDate(date.getDate() + days);
		var month = date.getMonth() + 1;
		var day = date.getDate();
		var mm = "'" + month + "'";
		var dd = "'" + day + "'";
		
		//单位数前面加0
		if(mm.length == 3) {
			month = "0" + month;
		}
		if(dd.length == 3) {
			day = "0" + day;
		}

		var time = date.getFullYear() + "-" + month + "-" + day
		return time;
    }
	
	jQuery().ready(function(){
		
		//变动生效日期
		jQuery("#"+zgsxrqfield).bindPropertyChange(function(){
			var zgsxrq_val = jQuery("#"+zgsxrqfield).val();
			
			
			if(jQuery("#"+khksrqfield).attr("type")=='hidden'){ 
				jQuery("#"+khksrqfield+"span").html(zgsxrq_val);
			}
			
			
		})
		
		//考核期限
		jQuery("#"+khqxfield).bindPropertyChange(function(){
			var zgsxrq_val = jQuery("#"+zgsxrqfield).val();//变动生效日期
			var khqxfield_val = jQuery("#"+khqxfield).val();//考核期限
			



			
			if(khqxfield_val == 0){
				var nextMonthDay = getNextMonth(zgsxrq_val,1);
				var nextMonthDaySubOne = addDate1(nextMonthDay, -1);
				if(jQuery("#"+khdqrfield).attr("type")=='hidden'){ 
					jQuery("#"+khdqrfield+"span").html(nextMonthDaySubOne);
				}else{
					jQuery("#"+khdqrfield).val(nextMonthDaySubOne);
				}

				if(jQuery("#"+khksrqfield).attr("type")=='hidden'){ 
					jQuery("#"+khksrqfield+"span").html(zgsxrq_val);
				}else{
					jQuery("#"+khksrqfield).val(zgsxrq_val);
				}
			}else if(khqxfield_val == 1){
				var nextMonthDay = getNextMonth(zgsxrq_val,2);
				var nextMonthDaySubOne = addDate1(nextMonthDay, -1);
				if(jQuery("#"+khdqrfield).attr("type")=='hidden'){ 
					jQuery("#"+khdqrfield+"span").html(nextMonthDaySubOne);
				}else{
					jQuery("#"+khdqrfield).val(nextMonthDaySubOne);
				}

				if(jQuery("#"+khksrqfield).attr("type")=='hidden'){ 
					jQuery("#"+khksrqfield+"span").html(zgsxrq_val);
				}else{
					jQuery("#"+khksrqfield).val(zgsxrq_val);
				}
			}else if(khqxfield_val == 2){
				var nextMonthDay = getNextMonth(zgsxrq_val,3);
				var nextMonthDaySubOne = addDate1(nextMonthDay, -1);
				if(jQuery("#"+khdqrfield).attr("type")=='hidden'){ 
					jQuery("#"+khdqrfield+"span").html(nextMonthDaySubOne);
				}else{
					jQuery("#"+khdqrfield).val(nextMonthDaySubOne);
				}

				if(jQuery("#"+khksrqfield).attr("type")=='hidden'){ 
					jQuery("#"+khksrqfield+"span").html(zgsxrq_val);
				}else{
					jQuery("#"+khksrqfield).val(zgsxrq_val);
				}
			}else if(khqxfield_val == 3){
				if(jQuery("#"+khdqrfield).attr("type")=='hidden'){ 
					jQuery("#"+khdqrfield+"span").html("");
				}else{
					jQuery("#"+khdqrfield).val("");
				}

				if(jQuery("#"+khksrqfield).attr("type")=='hidden'){ 
					jQuery("#"+khksrqfield+"span").html("");
				}else{
					jQuery("#"+khksrqfield).val("");
				}
			}

			
			/*
			if(khqxfield_val == 0){
				var addTime = addDate(zgsxrq_val, 30);
				if(jQuery("#"+khdqrfield).attr("type")=='hidden'){ 
					jQuery("#"+khdqrfield+"span").html(addTime);
				}else{
					jQuery("#"+khdqrfield).val(addTime);
				}
			}else if(khqxfield_val == 1){
				var addTime = addDate(zgsxrq_val, 60);
				if(jQuery("#"+khdqrfield).attr("type")=='hidden'){ 
					jQuery("#"+khdqrfield+"span").html(addTime);
				}else{
					jQuery("#"+khdqrfield).val(addTime);
				}
			}else if(khqxfield_val == 2){
				var addTime = addDate(zgsxrq_val, 90);
				if(jQuery("#"+khdqrfield).attr("type")=='hidden'){ 
					jQuery("#"+khdqrfield+"span").html(addTime);
				}else{
					jQuery("#"+khdqrfield).val(addTime);
				}
			}
			*/
			
		})






		
		
		
		
	})
	
	

	
	
</script>

